define(['jquery', 'bootstrap', 'backend', 'addtabs', 'table', 'echarts', 'echarts-theme', 'template'], function ($, undefined, Backend, Datatable, Table, Echarts, undefined, Template) {

    var Controller = {
			index: function () {
				//读取FastAdmin的更新信息
				$.ajax({
					url: Config.fastadmin.api_url + '/news/index',
					type: 'post',
					dataType: 'jsonp',
					success: function (ret) {
						$("#news-list").html(Template("newstpl", {news: ret.newslist}));
					}
				});
				$.ajax({
					url: Config.fastadmin.api_url + '/forum/discussion',
					type: 'post',
					dataType: 'jsonp',
					success: function (ret) {
						$("#discussion-list").html(Template("discussiontpl", {news: ret.discussionlist.slice(0,6)}));
					}
				});
			
				//打开网页然后就读取一次信息
				$.ajax({
						type: "post",
						url: Config.GameDB.http +'/admin/recharge/Api/GetgamingUser',
						dataType: "JSON",
						
						success: function (data) {
							var htmlstr="";
							//在线人数
							var onlinestr="";
							
							if(data['onlineUsers'] < data['room']['总计']['userCount']){
								data['onlineUsers'] = data['room']['总计']['userCount'];
							};
							$.each(data['room'], function (idx, obj) {
								htmlstr+="<tr>";
								htmlstr+="<td>"+idx;
								htmlstr+="</td>";
								htmlstr+="<td>"+obj.roomCount;
								htmlstr+="</td>";
								htmlstr+="<td>"+obj.userCount;
								htmlstr+="</td>";
								htmlstr+="<td><a href='usermanage/roomonline' class='btn-addtabs'>查看详情</a></td>";
								htmlstr+="</tr>";
								});
								
							$("#gamedata").html(htmlstr);//填充html
								onlinestr+="<div class='col-lg-4'>";
								onlinestr+="<legend><b>游戏中开房数</b><span STYLE='margin-left:20px;'>"+data['room']['总计']['roomCount']+"</span></legend></div>";
								onlinestr+="<div class='col-lg-4'>";
								onlinestr+="<legend><b>在线人数</b><span STYLE='margin-left:20px;'>"+data['room']['总计']['userCount']+"</span></legend></div>";
								onlinestr+="<div class='col-lg-4'>";
								onlinestr+="<legend><b>游戏中人数</b><span STYLE='margin-left:20px;'>"+data['onlineUsers']+"</span></legend></div>";
							$("#onlinedata").html(onlinestr);//填充html	     
						}
					
					});
			
				//html格式输出;
				setInterval(function () {
					$.ajax({
						type: "post",
						url: Config.GameDB.http +'/admin/recharge/Api/GetgamingUser',
						dataType: "JSON",
						
						success: function (data) {
							var htmlstr="";
							//在线人数
							var onlinestr="";
							
							if(data['onlineUsers'] < data['room']['总计']['userCount']){
								data['onlineUsers'] = data['room']['总计']['userCount'];
							};
							
							$.each(data['room'], function (idx, obj) {
								htmlstr+="<tr>";
								htmlstr+="<td>"+idx;
								htmlstr+="</td>";
								htmlstr+="<td>"+obj.roomCount;
								htmlstr+="</td>";
								htmlstr+="<td>"+obj.userCount;
								htmlstr+="</td>";
								htmlstr+="<td><a href='usermanage/roomonline' class='btn-addtabs'>查看详情</a></td>";
								htmlstr+="</tr>";
								});
								
							$("#gamedata").html(htmlstr);//填充html
								onlinestr+="<div class='col-lg-4'>";
								onlinestr+="<legend><b>游戏中开房数</b><span STYLE='margin-left:20px;'>"+data['room']['总计']['roomCount']+"</span></legend></div>";
								onlinestr+="<div class='col-lg-4'>";
								onlinestr+="<legend><b>在线人数</b><span STYLE='margin-left:20px;'>"+data['room']['总计']['userCount']+"</span></legend></div>";
								onlinestr+="<div class='col-lg-4'>";
								onlinestr+="<legend><b>游戏中人数</b><span STYLE='margin-left:20px;'>"+data['onlineUsers']+"</span></legend></div>";
							$("#onlinedata").html(onlinestr);//填充html	     
						}
					
					});
				}, 30000);
			},
			
    };

    return Controller;
});
